package com.lvyq.qrobot.service.impl;

import com.lvyq.qrobot.entity.SysEquip;
import com.lvyq.qrobot.entity.UserAttribute;
import com.lvyq.qrobot.mapper.UserAttributeMapper;
import com.lvyq.qrobot.model.receive.ReceiveMsg;
import com.lvyq.qrobot.service.UserAttributeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lvyq 角色属性
 * @version 1.0
 * Create by 2024-06-05 15:39
 */
@Service
public class UserAttributeServiceImpl implements UserAttributeService {

    @Resource
    public UserAttributeMapper userAttributeMapper;

    /**
     * @description 角色属性初始化
     * @author lvyq
     * @param[1] equips
     * @throws
     * @time 2024-06-05 15:46
     */
    @Override
    public void initAttribute(List<SysEquip> equips, ReceiveMsg vo) {
        UserAttribute attribute = new UserAttribute();
        //攻击
         Integer basicAttack=0;
        //气血 -角色初始气血+20
         Integer blood=20;
        //先攻
         Integer basicFirstAttack=0;
        //暴击
         Integer criticalStrike=0;
        //暴击威力
         Integer criticalStrikePower=0;
        //圣伤
         Integer holyInjury=0;
        //闪避
         Integer dodge=0;
        //命中
         Integer hit=0;
        //内力 -角色初始内力+3
         Integer internalForce=3;
        //防御
         Integer defense=0;
        //抗暴
         Integer antiRiot=0;
        for (SysEquip sysEquip : equips) {//攻击
            basicAttack = basicAttack + sysEquip.basicAttack;
            //气血
            blood = blood + sysEquip.blood;
            //先攻
            basicFirstAttack = basicFirstAttack + sysEquip.basicFirstAttack;
            //暴击
            criticalStrike = criticalStrike + sysEquip.criticalStrike;
            //暴击威力
            criticalStrikePower = criticalStrikePower + sysEquip.criticalStrikePower;
            //圣伤
            holyInjury = holyInjury + sysEquip.holyInjury;
            //闪避
            dodge = dodge + sysEquip.dodge;
            //命中
            hit = hit + sysEquip.hit;
            //内力
            internalForce = internalForce + sysEquip.internalForce;
            //防御
            defense = defense + sysEquip.defense;
            //抗暴
            antiRiot = antiRiot + sysEquip.antiRiot;
        }
        attribute.setBlood(blood);
        attribute.setBasicAttack(basicAttack);
        attribute.setAntiRiot(antiRiot);
        attribute.setDefense(defense);
        attribute.setDodge(dodge);
        attribute.setHit(hit);
        attribute.setGroupId(vo.groupId);
        attribute.setUserId(vo.userId);
        attribute.setCriticalStrike(criticalStrike);
        attribute.setHolyInjury(holyInjury);
        attribute.setBasicFirstAttack(basicFirstAttack);
        attribute.setInternalForce(internalForce);
        attribute.setCriticalStrikePower(criticalStrikePower);
        userAttributeMapper.insert(attribute);
    }

    /**
     * @description 获取信息
     * @author lvyq
     * @param[1] groupId
     * @param[2] userId
     * @throws
     * @return UserAttribute
     * @time 2024-06-05 16:12
     */
    @Override
    public UserAttribute getUserAttributeInfo(Integer groupId, Integer userId) {
        UserAttribute userAttribute =  userAttributeMapper.getUserAttributeInfo(groupId,userId);
        return userAttribute;
    }
}
